#pragma once
#include <QStandardPaths>
#include <QObject>
#include <QSettings>
#include "singleton.h"
#include "enum_file.h"

// 添加宏定义
// cloud
#define CLOUD_GROUP                             "Cloud"
#define KEY_USERNAME                            "userName"
#define KEY_USERPWD                             "passWd"
#define KEY_ACCOUNT_TYPE                        "accountType"
#define KEY_SERVERTAG                           "serverTag"
#define KEY_CONUTRY                             "country"
#define KEY_LOGIN_STATE                         "loginState"
#define KEY_REMEMBER_ME                         "rememberMe"

// launch
#define LAUNCH_GROUP                            "Launch"
#define KEY_LAUNCH_COUNT                        "launchCount"
#define KEY_LAUNCH_LANGUAGE                     "language"

// layout
#define LAYOUT_GROUP                            "Layout"
#define KEY_PAM_CHECK                           "pamChecked"
#define KEY_PSM_CHECK                           "psmChecked"
#define KEY_MODEL_SPACING                       "modelSpacing"
#define KEY_PLATFORM_MARGINS                    "platformMargins"
#define KEY_RSAZA_INDEX                         "rsazaIndex"
#define KEY_SBA_CHECK                           "sbaChecked"
#define KEY_SBH_CHECK                           "sbhChecked"
#define KEY_START_POSITION_INDEX                "startPositionIndex"
#define KEY_MTCAN_CHECK                         "mtcanChecked"

//qin -- punch(add holes)
#define PUNCH_GROUP                             "Punch"
#define KEY_PUNCH_OCD_SPINBOXTEXT               "ocdSpinBoxText"
#define KEY_PUNCH_ICD_SPINBOXTEXT               "icdSpinBoxText"
#define KEY_PUNCH_EL_SPINBOXTEXT                "elSpinBoxText"
#define KEY_PUNCH_GD_SPINBOXTEXT                "gdSpinBoxText"
#define KEY_PUNCH_DIRECTION_INDEX               "directionIndex"
#define KEY_PUNCH_KEEPHOLE_CHECK                "keepHoleChecked"

//qin -- hollow
#define HOLLOW_GROUP                            "Hollow"
#define KEY_HOLLOW_WT_SPINBOXTEXT               "wtSpinBoxText"
#define KEY_HOLLOW_ACCURACY_SPINBOXTEXT         "accuraySpinBoxText"
#define KEY_HOLLOW_DIRECTION_INDEX              "directionIndex"
#define KEY_HOLLOW_NBF_INDEX                    "nbfIndex"
#define KEY_HOLLOW_CELLSIZE_SPINBOXTEXT         "cellSizeSpinBoxText"
#define KEY_HOLLOW_SRADIUS_SPINBOXTEXT          "sRdiusSpinBoxText"

//qin -- recent file
#define RECENTOPENFILE_GROUP                    "RecentOpenFile"
#define KEY_RECENTOPENFILE_TEXT                 "recentOpenFileText"

// repair
#define REPAIR_GROUP                            "Repair"
#define KEY_MODEL_QUALITY_CHECK                 "modelQualityChecked"
#define KEY_SMRPD_CHECK                         "smrpdChecked"

// support
#define SUPPORT_GROUP                           "Support"
#define KEY_SUPPORT_CHECKBOX                    "ssmpdwsCheckBox"

// text
#define TEXT_GROUP                              "Text"
#define KEY_TEXT_ANGLE                          "textAngle"
#define KEY_TEXT_HEIGHT                         "textHeight"
#define KEY_TEXT_TEXT                           "textText"
#define KEY_FAMILY_INDEX                        "familyIndex"
#define KEY_FONT_POINT_INDEX                    "fontPointIndex"

// base config
#define BASE_CONFIG_GROUP                       "base_config"
#define KEY_CUSTOM_SUFFIX                       "custom_suffix"
#define KEY_INTELLIGENT_OPEN                    "intelligent_open"
#define KEY_FIRST_FAST_RESIN                    "first_fast_resin"
#define KEY_FIRST_HIGH_RESIN                    "first_high_resin"
#define KEY_TEST_ENVIRONMENT                    "test_environment"
#define KEY_ENVIRONMENT                         "environment"
#define KEY_UNDOVIEW                            "undoview"

// path config
#define FILE_PATH_CONFIG_GROUP                  "file_path_config"
#define FACEGEN_FILE_PATH                       "face_gen_path"
#define PWSP_FILE_PATH                          "pwsp_path"
#define PWSR_FILE_PATH                          "pwsr_path"
#define MODEL_FILE_PATH                         "model_path"

class GlobalConfig : public QObject
{
    Q_OBJECT
public:

    explicit GlobalConfig() {};
    ~GlobalConfig() {};

    SINGLETON_DEFINE(GlobalConfig)

    void initConfig();
    // 更新新特性, 只做+法
    void updateNewFeatures();
    Q_INVOKABLE QVariant readConfig(int param);
    Q_INVOKABLE QVariant writeConfig(int param, QVariant var);
    Q_INVOKABLE void saveConfig();

signals:
    void languageChanged();

private:
    void initData(QString group);
    QVariant operaConfig(CommonEnum::ConfigParam param, QVariant var);
    template<typename T>
    QVariant formatValue(T& var, QVariant& value);

private:
    QSettings *mSetting = nullptr;
    std::map<QString, std::map<QString, QVariant>> m_fileMap;
};
